<?php
/**
 * Created by PhpStorm.
 * User: charles
 * Date: 2017-11-13
 * Time: 06:46
 */

namespace App\Http\Controllers\LA;


use App\Http\Controllers\Controller;
use App\Models\Domain;
use Carbon\Carbon;
use Illuminate\Http\Request;

class DomainController extends Controller
{
    public function index()
    {
        $domains = Domain::query()
            ->orderBy('id', 'desc')
            ->paginate(20);
        return view('la.domains.index', compact('domains'));
    }

    public function enable($id)
    {
        Domain::query()
            ->where('id', $id)
            ->update(['status' => 1]);
        return redirect()->back();
    }

    public function disable($id)
    {
        Domain::query()
            ->where('id', $id)
            ->update(['status' => 0]);
        return redirect()->back();
    }

    public function show($id)
    {
        $domain = Domain::find($id);
        return view('la.domains.show', compact('domain'));
    }

    public function destroy($id)
    {
        Domain::query()
            ->where('id', $id)
            ->delete();
        return redirect()->back();
    }

    public function update(Request $request)
    {
        $domain = Domain::find($request->id);
        if (null === $domain) {
            $domain = new Domain();
        }
        $domain->fill($request->all());
        $domain->save();
        return redirect('/admin/domain');
    }
}